package com.example.qu_tao.View;

import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.qu_tao.R;

public class YunFeiMoBanActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yunfeimoban);

        // 初始化视图
        initViews();

        // 设置点击监听
        setClickListeners();
    }

    private void initViews() {
        // 返回按钮
        findViewById(R.id.ivBack).setOnClickListener(v -> finish());
    }

    private void setClickListeners() {
        // 全国包邮
        LinearLayout llNationwideFree = findViewById(R.id.llNationwideFree);
        TextView tvNationwideDetail = findViewById(R.id.tvNationwideDetail);

        llNationwideFree.setOnClickListener(v -> selectTemplate(1));
        tvNationwideDetail.setOnClickListener(v -> showTemplateDetail(1));

        // 部分包邮
        LinearLayout llPartialFree = findViewById(R.id.llPartialFree);
        TextView tvPartialDetail = findViewById(R.id.tvPartialDetail);

        llPartialFree.setOnClickListener(v -> selectTemplate(2));
        tvPartialDetail.setOnClickListener(v -> showTemplateDetail(2));

        // 运费自理
        LinearLayout llSelfPaid = findViewById(R.id.llSelfPaid);
        TextView tvSelfPaidDetail = findViewById(R.id.tvSelfPaidDetail);

        llSelfPaid.setOnClickListener(v -> selectTemplate(3));
        tvSelfPaidDetail.setOnClickListener(v -> showTemplateDetail(3));
    }

    private void selectTemplate(int templateType) {
        String templateName = "";
        switch (templateType) {
            case 1:
                templateName = "全国包邮";
                break;
            case 2:
                templateName = "除港澳台、新疆、西藏地区包邮";
                break;
            case 3:
                templateName = "运费自理";
                break;
        }

        Toast.makeText(this, "已选择：" + templateName, Toast.LENGTH_SHORT).show();

        // 这里可以添加保存选择的运费模板的逻辑
        // saveSelectedTemplate(templateType);

        // 返回到上一页
        finish();
    }

    private void showTemplateDetail(int templateType) {
        Intent intent = new Intent(this, ChaKanXiangQingActivity.class);
        intent.putExtra("template_type", templateType);
        startActivity(intent);
    }
}
